<?php
App::uses('AppController', 'Controller');
/**
 * Calendarios Controller
 *
 * @property Calendario $Calendario
 */
class CalendariosController extends AppController {

	public function beforeFilter(){
		parent::beforeFilter();
		$this->Auth->allow('diasDoAnuncio');
	}


	public function dias_livres($id = null) {
		$this->Calendario->Anuncio->id = $id;
		if (!$this->Calendario->Anuncio->exists()|| 
		!$this->Calendario->Anuncio->anuncioPertenceAoUsuario($this->Calendario->Anuncio->read('usuario_id' ,$id), $this->usuarioAtual['id_usuarios'])) {
			throw new NotFoundException(__('Invalid calendario'));
		}
		if ($this->request->is('post') || $this->request->is('put')) {
			$statusSalvar = $this->Calendario->salvarDatas($this->request->data['Calendario']);
			$remover = $this->Calendario->remocao($this->request->data['Calendario']);
			if ($statusSalvar) {
				$this->Session->setFlash(__('The calendario has been saved'));
			} else {
				$this->Session->setFlash(__('The calendario could not be saved. Please, try again.'));
			}
		} else {
			$this->request->data = $this->Calendario->read(null, $id);
		}
		$anuncios = $this->Calendario->Anuncio->find('list');
		$this->set(compact('anuncios'));
		$this->set('anuncio_id', $id);
	}
	
	public function diasDoAnuncio($id){
		return $this->Calendario->diasOcupados($id);
	}
}
